package org.wyp.wang.realm;

import org.apache.shiro.authc.*;
import org.apache.shiro.realm.Realm;

/**
 * Created by lenovo on 2017/6/26.
 */
public class RvpRealm implements Realm{
    public String getName() {
        return "rvpRealm";
    }

    public boolean supports(AuthenticationToken authenticationToken) {
        return authenticationToken instanceof UsernamePasswordToken;
    }

    public AuthenticationInfo getAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        String principal = authenticationToken.getPrincipal().toString();
        String credential = new String((char[]) authenticationToken.getCredentials());
        if (!principal.equals("rvp")){
            throw new UnknownAccountException();
        }
        if (!credential.equals("321")){
            throw new IncorrectCredentialsException();
        }
        return new SimpleAuthenticationInfo(principal,credential,getName());
    }
}
